package net.qiqbframework.loadhanding;

import net.qiqbframework.messaging.GenericMessage;
import net.qiqbframework.messaging.MessageDecorator;
import net.qiqbframework.modelling.domain.AggregateModel;

import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.HashMap;


public class BatchGenericLoadMessage<T> extends MessageDecorator<Collection<T>> implements LoadMessage<Collection<T>> {

    private final String businessIdName;


    private final AggregateModel aggregateModel;


    public BatchGenericLoadMessage(@Nonnull Collection<T> businessId, String businessIdName, @Nonnull AggregateModel<?> aggregateModel) {
        super(new GenericMessage<>(businessId, new HashMap<>()));
        this.aggregateModel = aggregateModel;
        this.businessIdName = businessIdName;
    }

    @Override
    public boolean isBatch() {
        return true;
    }

    @Override
    protected String describeType() {
        return "BatchGenericLoadMessage";
    }


    @Override
    public String getAggregateName() {
        return aggregateModel.modelName();
    }

    @Override
    public String getBusinessIdName() {
        return businessIdName;
    }

    @Override
    public Class<?> getAggregateType() {
        return aggregateModel.entityClass();
    }

    @Override
    public AggregateModel<?> getAggregateModel() {
        return aggregateModel;
    }


}
